package org.springcloud.wisdom.spring_01_canteen.loginmsg.controller;


import org.springcloud.wisdom.spring_01_canteen.common.bean.ResponseData;
import org.springcloud.wisdom.spring_01_canteen.common.bean.ResponseData2;
import org.springcloud.wisdom.spring_01_canteen.common.bean.ResultCode;
import org.springcloud.wisdom.spring_01_canteen.login.entity.*;


public class BaseController {
    public ResponseData<Boolean> returnBoolean(Boolean result) {
        ResponseData<Boolean> responseData = new ResponseData<>() ;
        responseData.setData(result);
        if(result) {
            responseData.setErrorCode(ResultCode.SUCCESS.getCode());
            responseData.setMsg(String.valueOf(ResultCode.SUCCESS.getMessage()));
        } else {
            responseData.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            responseData.setMsg(String.valueOf(ResultCode.COMMON_FAIL.getMessage()));
        }
        return responseData ;
    }
    public ResponseData2<Object> returnObject(Object data) {
        ResponseData2<Object> responseData = new ResponseData2<>() ;
        responseData.setData(data);

        if (data instanceof Student) {
            responseData.setRole("student");
        } else if (data instanceof Mall) {
            responseData.setRole("mall");
        }else if (data instanceof Admin) {
            responseData.setRole("admin");
        }else if (data instanceof Teacher) {
            responseData.setRole("teacher");
        }else if (data instanceof Freshman) {
            responseData.setRole("freshman");
        }else {
            responseData.setRole("other");
        }
        if(null != data) {
            responseData.setErrorCode(ResultCode.SUCCESS.getCode());
            responseData.setMsg(String.valueOf(ResultCode.SUCCESS.getMessage()));
        } else {
            responseData.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            responseData.setMsg(String.valueOf(ResultCode.COMMON_FAIL.getMessage()));
        }
        return responseData ;
    }
    public ResponseData<Object> returnObject2(Object data) {
        ResponseData<Object> responseData = new ResponseData<>() ;
        responseData.setData(data);
        if(null != data) {
            responseData.setErrorCode(ResultCode.SUCCESS.getCode());
            responseData.setMsg(String.valueOf(ResultCode.SUCCESS.getMessage()));
        } else {
            responseData.setErrorCode(ResultCode.COMMON_FAIL.getCode());
            responseData.setMsg(String.valueOf(ResultCode.COMMON_FAIL.getMessage()));
        }
        return responseData ;
    }
}
